#include "Selectbgcolorwidget.h"

#include "ui_Selectbgcolorwidget.h"

#include <QBitmap>
#include <QPainter>

SelectBgColorWidget::SelectBgColorWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SelectBgColorWidget)
{
    ui->setupUi(this);

    initUI();
}

void SelectBgColorWidget::initUI() {
    setAttribute(Qt::WA_DeleteOnClose);
    setWindowFlags(Qt::FramelessWindowHint | windowFlags() | Qt::Tool);
    setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);

    QBitmap bmp(this->size());
    bmp.fill();
    QPainter p(&bmp);
    p.setPen(Qt::NoPen);
    p.setBrush(Qt::black);
    p.drawRoundedRect(bmp.rect(),5,5);
    setMask(bmp);

    ui->clearBg->setStyleSheet("border:2px solid #4381ff;background-image: url(:/new/icon/color/bg_transparent_default.png);");

    connect(ui->blackBg, SIGNAL(clicked()), this, SLOT(selectBlackBg()));
    connect(ui->whiteBg, SIGNAL(clicked()), this, SLOT(selectWhiteBg()));
    connect(ui->clearBg, SIGNAL(clicked()), this, SLOT(selectClearBg()));
}

void SelectBgColorWidget::selectBlackBg() {
    ui->blackBg->setStyleSheet("border:2px solid #4381ff;background-image: url(:/new/icon/color/color_black_default.png);");
    ui->whiteBg->setStyleSheet("border:2px solid #ffffff;border-image: url(:/new/icon/color/color_white_default.png);");
    ui->clearBg->setStyleSheet("border:0px solid #4381ff;background-image: url(:/new/icon/color/bg_transparent_default.png);");

    emit changeDrawBg("rgb(0,0,0,255)");
}

void SelectBgColorWidget::selectWhiteBg() {
    ui->blackBg->setStyleSheet("border:2px solid #000000;background-image: url(:/new/icon/color/color_black_default.png);");
    ui->whiteBg->setStyleSheet("border:2px solid #4381ff;background-image: url(:/new/icon/color/color_white_default.png);");
    ui->clearBg->setStyleSheet("border:0px solid #4381ff;background-image: url(:/new/icon/color/bg_transparent_default.png);");

    emit changeDrawBg("rgb(255,255,255,255)");
}

void SelectBgColorWidget::selectClearBg() {
    ui->blackBg->setStyleSheet("border:2px solid #000000;background-image: url(:/new/icon/color/color_black_default.png);");
    ui->whiteBg->setStyleSheet("border:2px solid #4381ff;border-image: url(:/new/icon/color/color_white_default.png);");
    ui->clearBg->setStyleSheet("border:2px solid #4381ff;background-image: url(:/new/icon/color/bg_transparent_default.png);");

    emit changeDrawBg("rgb(255,255,255,0)");
}

SelectBgColorWidget::~SelectBgColorWidget()
{
    delete ui;
}
